/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package byblos.util;

import java.lang.annotation.Annotation;

/**
 *
 * @author marano
 */
public class ReflexaoUtil {

    public static boolean implementa(Class classe, Class interfacee) {
        if (classe == Object.class) {
            return false;
        } else {
            Class[] interfaces = classe.getInterfaces();
            for (Class i : interfaces) {
                if (i == interfacee) {
                    return true;
                }
            }
        }
        return implementa(classe.getSuperclass(), interfacee);
    }

    public static <T extends Annotation> T getAnotacao(Class<T> anotacao, Class classe) {
        if (classe == Object.class) {
            return null;
        } else {
            Annotation[] anotacoes = classe.getDeclaredAnnotations();
            for (Annotation a : anotacoes) {
                if (a.annotationType() == anotacao) {
                    return (T) a;
                }
            }
        }
        return getAnotacao(anotacao, classe.getSuperclass());
    }
}
